//
//  SQLiteManager.swift
//  07-FMDB基本使用
//
//  Created by J on 16/7/31.
//  Copyright © 2016年 J. All rights reserved.
//

import UIKit
import FMDB
class SQLiteManager: NSObject {

    static let shareInstance :SQLiteManager = SQLiteManager()
    var db :FMDatabase!
//    var db :FMDatabaseQueue!

    
    override init() {
        super.init()
        
        //0 获取保存数据库文件的路径
        guard let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).last else{
            return
        }
        //1.打开数据
        let filePath = (path as NSString).stringByAppendingPathComponent("acfun.sqlite")
//         db =  FMDatabaseQueue(path:filePath)
        db =  FMDatabase(path:filePath)

        
        if !db.open(){
            return
        }
        
        //2.创建表
        self.createTable()
        
    }
    
    func createTable(){
        //1.编写SQL语句
        let sql = "create table if not exists t_history (id integer primary key autoincrement, name text, age integer);"
        //2.执行SQL语句
        db.executeUpdate(sql, withArgumentsInArray: nil)

//        db.executeUpdate(sql, withArgumentsInArray: nil)
//            db.inDatabase { (db) in
        
//        }
    }
    

    
    
}
